package com.cc.fajian.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cc.fajian.pojo.QuestionOptionsInfoPo;
import com.cc.fajian.pojo.User;
import com.cc.fajian.service.IQusetionService;
import com.cc.fajian.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/test")
public class UserController {
	@Resource
	private IUserService userService;
	@Resource
	private IQusetionService queService;
	
	@RequestMapping("/showUser")
	public String toIndex(HttpServletRequest request,Model model){
		int userId = Integer.parseInt(request.getParameter("id"));
		User user = this.userService.getUserById(userId);
		model.addAttribute("user", user);
		return "showUser";
	}
	@RequestMapping(value = "/testResponseBody",method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> index3(HttpServletRequest request, HttpServletResponse response){
		response.setContentType("text/html");
		String id = request.getParameter("questionId");
		QuestionOptionsInfoPo po = new QuestionOptionsInfoPo();
		po.setQuestionId("1");
		po.setQuestionType("01");
		po = queService.getQueById(po);
		System.out.println(po.getOptionsType());
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("success",true);
		Map<String,Object> map2 = new HashMap<String, Object>();
		map2.put("选项1内容","55");
		map2.put("选项2内容","56");
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		list.add(map2);
		map.put("options",list);
		map.put("text","问题内容");
		return map;
	}

}
